﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TjZheng.Framework;
using TjZheng.WeiXin.DataEntity;

namespace TjZheng.WeiXin.SDK.Pay
{
    public class PayModeOne : NativePay
    {
        public PayModeOne(string appId)
            : base(appId)
        {

        }
        public PayModeOne(int merchantId)
            : base(merchantId)
        {

        }
        public PayModeOne(MerchantInfo objMerchantInfo)
            : base(objMerchantInfo)
        {

        }
        public override InvokeResult CreatePayUrl(WxPayPackage objWxPayPackage)
        {
            if (objWxPayPackage == null)
            {
                throw new ArgumentNullException("PayModeOne.WxPayPackage");
            }

            objWxPayPackage.SetValue("appid", this.MerchantInfo.AppId);//公众帐号id
            objWxPayPackage.SetValue("mch_id", this.MerchantInfo.MChId);//商户号
            objWxPayPackage.SetValue("time_stamp", WxPayApi.GenerateTimeStamp());//时间戳
            objWxPayPackage.SetValue("nonce_str", WxPayApi.GenerateNonceStr());//随机字符串

            objWxPayPackage.SetValue("sign", objWxPayPackage.CreateSign(this.MerchantInfo.MKey));//签名

            string str = "";
            foreach (string key in objWxPayPackage.Keys)
            {
                str += key + "=" + objWxPayPackage.GetValue(key) + "&";
            }
            str = str.Trim('&');

            return new InvokeResult 
            {
                Data = "weixin://wxpay/bizpayurl?" + str
            };

        }
    }
}
